<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<c:set var="overDay" value="${loanVO.repay.overDay}"/>

<div class="bjui-pageContent" style="top: 0; bottom: 35px;">

    <c:if test="${!isInfo}">
        <c:if test="${isAdvance}">
            <%--提前还款--%>
            <div data-layout-h="0" class="bjui-row col-2">

                <label class="row-label">
                    标的名称:
                </label>
                <div class="row-input">
                        ${loanVO.loan.fullName}
                </div>

                <label class="row-label">
                    借款金额:
                </label>
                <div class="row-input">
                        ${loanVO.loan.loanAmountD}元
                </div>

                <label class="row-label">
                    标的编号:
                </label>
                <div class="row-input">
                        ${loanVO.loan.loanNumber}
                </div>

                <label class="row-label">
                    应还本金:
                </label>
                <div class="row-input">
                        ${loanVO.loan.loanAmountD}元
                </div>

                <label class="row-label">
                    借款人:
                </label>
                <div class="row-input">
                        ${loanVO.loan.userName}
                </div>

                <label class="row-label">
                    应付利息:
                </label>
                <div class="row-input">
                        ${loanVO.repay.nowInterestD}元
                </div>

                <label class="row-label">
                    借款期限:
                </label>
                <div class="row-input">
                        ${loanVO.loan.loanTime}天
                </div>

                <label class="row-label">
                    借款天数:
                </label>
                <div class="row-input">
                        ${loanVO.repay.loanedDay}天
                </div>

                <label class="row-label">
                    应该还款时间:
                </label>
                <div class="row-input">
                    <fmt:formatDate value="${loanVO.repay.shouldRepayDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
                </div>

                <label class="row-label">
                    违约金:
                </label>
                <div class="row-input">
                        ${loanVO.repay.compensateMoneyD}元
                </div>

                <label class="row-label">
                    开始计息时间:
                </label>
                <div class="row-input">
                    <fmt:formatDate value="${loanVO.repay.beginRepayDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
                </div>

                <label class="row-label">
                    还款金额:
                </label>
                <div class="row-input">
                        ${loanVO.repay.realRepayMoneyD}元
                </div>
            </div>
        </c:if>
        <c:if test="${!isAdvance}">
            <%--<c:if test="${loanVO.repay.overDay>0}">--%>
            <%--还款,逾期还款--%>
            <div data-layout-h="0" class="bjui-row col-2">
                <label class="row-label">
                    标的名称:
                </label>
                <div class="row-input">
                        ${loanVO.loan.fullName}
                </div>

                <label class="row-label">
                    借款金额:
                </label>
                <div class="row-input">
                        ${loanVO.loan.loanAmountD}元
                </div>

                <label class="row-label">
                    标的编号:
                </label>
                <div class="row-input">
                        ${loanVO.loan.loanNumber}
                </div>

                <label class="row-label">
                    应还本金:
                </label>
                <div class="row-input">
                        ${loanVO.loan.loanAmountD}元
                </div>

                <label class="row-label">
                    借款人:
                </label>
                <div class="row-input">
                        ${loanVO.loan.userName}
                </div>

                <label class="row-label">
                    应付利息:
                </label>
                <div class="row-input">
                        ${loanVO.repay.nowInterestD}元
                </div>

                <label class="row-label">
                    借款期限:
                </label>
                <div class="row-input">
                        ${loanVO.loan.loanTime}天
                </div>

                <label class="row-label">
                    逾期天数:
                </label>
                <div class="row-input">
                        ${loanVO.repay.overDay}天
                </div>

                <label class="row-label">
                    应该还款时间:
                </label>
                <div class="row-input">
                    <fmt:formatDate value="${loanVO.repay.shouldRepayDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
                </div>

                <label class="row-label">
                    逾期罚金:
                </label>
                <div class="row-input">
                        ${loanVO.repay.overD}元
                </div>

                <label class="row-label">
                    开始计息时间:
                </label>
                <div class="row-input">
                    <fmt:formatDate value="${loanVO.repay.beginRepayDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
                </div>

                <label class="row-label">
                    还款金额:
                </label>
                <div class="row-input">
                        ${loanVO.repay.realRepayMoneyD}元
                </div>
            </div>
        </c:if>
    </c:if>

    <c:if test="${isInfo}">
        <%--还款详情--%>
        <div data-layout-h="0" class="bjui-row col-3">
            <label class="row-label">
                应该还款时间:
            </label>
            <div class="row-input">
                <fmt:formatDate value="${loanVO.repay.shouldRepayDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
            </div>

            <label class="row-label">
                应还本金:
            </label>
            <div class="row-input">
                    ${loanVO.loan.loanAmountD}元
            </div>

            <c:if test="${overDay>0}">
                <label class="row-label">
                    逾期天数:
                </label>
                <div class="row-input">
                        ${loanVO.repay.overDay}天
                </div>
            </c:if>
            <c:if test="${overDay==null||overDay<0}">
                <label class="row-label">
                    借款天数:
                </label>
                <div class="row-input">
                        ${loanVO.repay.loanedDay}天
                </div>
            </c:if>

            <label class="row-label">
                实际还款时间:
            </label>
            <div class="row-input">
                <fmt:formatDate value="${loanVO.repay.realRepayDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
            </div>

            <label class="row-label">
                应付利息:
            </label>
            <div class="row-input">
                    ${loanVO.repay.nowInterestD}元
            </div>

            <c:if test="${overDay>0}">
                <label class="row-label">
                    逾期罚金:
                </label>
                <div class="row-input">
                        ${loanVO.repay.overD}元
                </div>
            </c:if>
            <c:if test="${overDay==null||overDay<0}">
                <label class="row-label">
                    违约金:
                </label>
                <div class="row-input">
                        ${loanVO.repay.compensateMoneyD}元
                </div>
            </c:if>

            <label class="row-label">
                还款金额:
            </label>
            <div class="row-input">
                    ${loanVO.repay.realRepayMoneyD}元
            </div>
        </div>
    </c:if>

    <%--下面是表格部分--%>
    <c:if test="${loanVO.repayUserPaging.totalCount>0}">
        <table class="table table-bordered" style="width: 100%">
            <thead>
            <tr>
                <td>投资人</td>
                <td>本金</td>
                <td>利息</td>
                <td>逾期罚息</td>
                <td>违约金</td>
                <td>还款金额</td>
            </tr>
            </thead>
            <tbody>
            <c:set value="0" var="buyMoneyD_sum"/>
            <c:set value="0" var="nowInterestD_sum"/>
            <c:set value="0" var="overD_sum"/>
            <c:set value="0" var="compensateMoneyD_sum"/>
            <c:set value="0" var="realRepayMoneyD_sum"/>
            <c:forEach items="${loanVO.repayUserPaging.list}" var="repayUser">
                <tr>
                    <td>
                        <a href="javascript:userInfo('${repayUser.userId}','${repayUser.userName}')">${repayUser.userName}</a>
                    </td>
                    <td>
                            ${repayUser.buyMoneyD}
                    </td>
                    <td>
                            ${repayUser.nowInterestD}
                    </td>
                    <td>
                            ${repayUser.overD}
                    </td>
                    <td>
                            ${repayUser.compensateMoneyD}
                    </td>
                    <td>
                            ${repayUser.realRepayMoneyD}
                    </td>
                </tr>
                <c:set value="${buyMoneyD_sum+repayUser.buyMoneyD}" var="buyMoneyD_sum"/>
                <c:set value="${nowInterestD_sum+repayUser.nowInterestD}" var="nowInterestD_sum"/>
                <c:set value="${overD_sum+repayUser.overD}" var="overD_sum"/>
                <c:set value="${compensateMoneyD_sum+repayUser.compensateMoneyD}" var="compensateMoneyD_sum"/>
                <c:set value="${realRepayMoneyD_sum+repayUser.realRepayMoneyD}" var="realRepayMoneyD_sum"/>
            </c:forEach>
            </tbody>
            <tfoot>
            <tr>
                <td>合计</td>
                <td>
                    <fmt:formatNumber value="${buyMoneyD_sum}" pattern="###0.00"/>
                </td>
                <td>
                    <fmt:formatNumber value="${nowInterestD_sum}" pattern="###0.00"/>
                </td>
                <td>
                    <fmt:formatNumber value="${overD_sum}" pattern="###0.00"/>
                </td>
                <td>
                    <fmt:formatNumber value="${compensateMoneyD_sum}" pattern="###0.00"/>
                </td>
                <td>
                    <fmt:formatNumber value="${realRepayMoneyD_sum}" pattern="###0.00"/>
                </td>
            </tr>
            </tfoot>
        </table>
    </c:if>
</div>

<c:if test="${!isInfo}">
    <div class="bjui-pageFooter">
        <ul>
            <li>
                <button type="button" class="btn-close">取消</button>
            </li>
            <li>
                <c:if test="${!isAdvance}">
                    <c:if test="${overDay>0}">
                        <button type="button" class="btn-blue" onclick="execRepay()">逾期还款</button>
                    </c:if>
                    <c:if test="${overDay==0}">
                        <button type="button" class="btn-blue" onclick="execRepay()">还款</button>
                    </c:if>
                    <c:if test="${overDay==null||overDay<0}">
                        <button type="button" class="btn-close btn-orange">未到还款日,请使用提前还款</button>
                    </c:if>
                </c:if>
                <c:if test="${isAdvance}">
                    <c:if test="${overDay>0}">
                        <button type="button" class="btn-close btn-orange">该标已经逾期,请使用还款</button>
                    </c:if>
                    <c:if test="${overDay==0}">
                        <button type="button" class="btn-close btn-orange">该标今天还款,请使用还款</button>
                    </c:if>
                    <c:if test="${overDay==null||overDay<0}">
                        <button type="button" class="btn-blue" onclick="execRepay()">提前还款</button>
                    </c:if>
                </c:if>
            </li>
        </ul>
    </div>
</c:if>

<c:if test="${!isInfo}">
    <script>
        function execRepay() {
            var loanId = ${loanId};
            var isAdvance = ${isAdvance};

            if (!loanId || isAdvance === undefined) {
                BJUI.alertmsg('error', "标的信息有误", {
                    okCall: function () {
                        BJUI.navtab('refresh');
                    }
                });
                return;
            }

            var openURL = "/admin/loan/repay/ajax/repay";

            BJUI.ajax('doajax', {
                url: openURL,
                data: {
                    loanId: loanId,
                    isAdvance: isAdvance
                },
                loadingmask: true,
                callback:function (data) {
                    var haveError = data.haveError;
                    if (haveError === true || haveError === 'true'){
                        BJUI.alertmsg('error', data.message, {
                            okCall: function() {
                                BJUI.dialog('close','repay'+loanId);
                                BJUI.navtab('refresh');
                            }
                        });
                        return;
                    }
                    BJUI.alertmsg('ok', data.message, {
                        okCall: function() {
                            BJUI.dialog('close','repay'+loanId);
                            BJUI.navtab('refresh');
                        }
                    });
                }
            })
        }
    </script>
</c:if>